import walf
import walf
import funksvd
import pandas as pd
import matplotlib

from final.getFuncton import get_train

matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

import os
import numpy as np

w=[]
x=[]
y=[]
z = np.arange(0, 50)
data_=pd.read_csv("ratings.csv",sep="\s+")
i=0
while i<50:
        data = data_
        all = get_train(data)
        train = all[0]
        test = all[1]
        data = train
        try:

            w.append(walf.walf(data,test))
            x.append(walf.walf1(data,test))
            y.append(walf.walf2(data, test))
            i=i+1
        except Exception:
            continue
a=plt.plot(z, w, label='none')
b=plt.plot(z, x, label='item')
c=plt.plot(z, y, label='user')
plt.legend()
print(np.mean(w),np.var(w))
print(np.mean(x),np.var(x))
print(np.mean(y),np.var(y))
plt.show()
